package org.streets.commons.util;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * Utility method for converting Enumeration to an Iterator
 * class.  If you attempt to remove() an Object from the iterator, it will
 * throw an UnsupportedOperationException. Added for use by TagLib so
 * Enumeration can be supported
 *
 */

public class IteratorAdapter<T> implements Iterator<T> {

    private java.util.Enumeration<T> enumrtn;

    public IteratorAdapter(java.util.Enumeration<T> enumrtn) {
        this.enumrtn = enumrtn;
    }

    public boolean hasNext() {
        return enumrtn.hasMoreElements();
   }

    public T next() {
        if (!enumrtn.hasMoreElements()) {
            throw new NoSuchElementException("IteratorAdaptor.next() has no more elements");
        }
        return enumrtn.nextElement();
    }
    
    public void remove() {
        throw new java.lang.UnsupportedOperationException("Method IteratorAdaptor.remove() not implemented");
    }
}
